import paramiko


def remote_exec(ip, port, user, pwd, cmd):
    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    ssh.connect(hostname=ip, port=port, username=user, password=pwd)

    stdin, stdout, stderr = ssh.exec_command(cmd)

    result = stdout.read()
    if result:
        print('---------- %s ----------' % ip)
        print(result.decode())


    result2 = stderr.read()
    if result2:
        print('---------- %s ----------' % ip)
        print(result2.decode())

    ssh.close()
